const Router = require('koa-router')
const controller = require('../controller')
const router = new Router()
const github = require('../plugins/github-oauth')
const authRequired = require('../middleware/auth-required')

router.get('/', async ctx => {
  ctx.body = {
    name: 'MarkDoc Server'
  }
})

router.get('/home', authRequired, async ctx => {
  const loginUser = await ctx.getLoginUser()

  ctx.body = {
    session: ctx.session,
    user: loginUser
  }
})

github.use(router, controller.user.loginGithub)

module.exports = router
